package cn.itcast.order;

import cn.itcast.client.UserClient;
import cn.itcast.config.DefaultFeignConfigration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
//开启Feign功能
@EnableFeignClients(
        defaultConfiguration = DefaultFeignConfigration.class,
        clients = {UserClient.class})
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
        System.err.println("order-service is runnning...");
    }

    /**
     * 注册RestTemplate实例
     * @return
     */
    @Bean
    @LoadBalanced   //负载均衡
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 修改负载均衡规则：ZoneAvoidanceRule(默认) --> RandomRule
     * @return
     */
    /*@Bean
    public IRule randomRule() {
        return new RandomRule();
    }*/
}